(() => {
    const btn = document.createElement("button");
    btn.style.position = "fixed";
    btn.style.left = "100px";
    btn.style.bottom = "100px";
    btn.style.zIndex = "10000";
    document.body.appendChild(btn);
    btn.innerText = "启动"
    const input = document.createElement("input");
    input.style.position = "fixed";
    input.style.left = "100px";
    input.style.bottom = "70px";
    input.style.zIndex = "10000"
    input.value = "5-10"
    document.body.appendChild(input)
    let flag = false;
    let time;
    const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
    const start = async () => {
        if (!flag) return;
        const [a, b] = input.value.split("-").map(e => parseInt(e));
        let timea = a;
        let timeb = b;
        if (isNaN(a) || isNaN(b) || b < a || b < 1 || a < 1) {
            timea = 1;
            timeb = 5;
            input.value = "1-5";
        }
        btn.innerText = "关闭"
        let buttons = Array.from(document.getElementsByTagName("button"));
        const submit = buttons.find(e => e.innerText === "提交任务");
        submit.click();
        await sleep(500);
        buttons = Array.from(document.getElementsByTagName("button"));
        buttons.find(e => e.innerText === "确 定").click();
        await sleep((Math.random() * (b - a) + a) * 1000);
        start();
    }
    const close = () => {
        btn.innerText = "启动"
        clearInterval(time);
    }
    btn.onclick = () => {
        flag = !flag;
        if (flag) start();
        else close()
    }
})()